package com.tencent.mm.opensdk.modelmsg;

import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;

import com.tencent.mm.opensdk.modelmsg.WXMediaMessage.IMediaObject;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;

public class WXImageObject implements IMediaObject {
    private static final int CONTENT_LENGTH_LIMIT = 10485760;
    private static final int PATH_LENGTH_LIMIT = 10240;
    private static final String TAG = "MicroMsg.SDK.WXImageObject";
    public byte[] imageData;
    public String imagePath;

    public WXImageObject() {

    }

    public WXImageObject(Bitmap arg5) {

        try {
            ByteArrayOutputStream v0_1 = new ByteArrayOutputStream();
            arg5.compress(Bitmap.CompressFormat.JPEG, 85, ((OutputStream)v0_1));
            this.imageData = v0_1.toByteArray();
            v0_1.close();
        }
        catch(Exception v0) {
            Log.e("MicroMsg.SDK.WXImageObject", "WXImageObject <init>, exception:" + v0.getMessage());
        }
    }

    public WXImageObject(byte[] arg1) {

        this.imageData = arg1;
    }

    public boolean checkArgs() {
        int v3 = 10485760;
        boolean v0 = false;
        if(this.imageData == null || this.imageData.length == 0) {
            if(this.imagePath != null && this.imagePath.length() != 0) {
            }else {
                Log.e("MicroMsg.SDK.WXImageObject", "checkArgs fail, all arguments are null");
                return false;
            }
        }
        if(this.imageData != null && this.imageData.length > v3) {
            Log.e("MicroMsg.SDK.WXImageObject", "checkArgs fail, content is too large");
            return v0;
        }

        if(this.imagePath != null && this.imagePath.length() > 10240) {
            Log.e("MicroMsg.SDK.WXImageObject", "checkArgs fail, path is invalid");
            return v0;
        }

        if(this.imagePath != null && this.getFileSize(this.imagePath) > v3) {
            Log.e("MicroMsg.SDK.WXImageObject", "checkArgs fail, image content is too large");
            return v0;
        }

        return true;
    }

    private int getFileSize(String arg4) {
        int v0 = 0;
        if(arg4 != null && arg4.length() != 0) {
            File v1 = new File(arg4);
            if(v1.exists()) {
                v0 = ((int)v1.length());
            }
        }

        return v0;
    }

    public void serialize(Bundle arg3) {
        arg3.putByteArray("_wximageobject_imageData", this.imageData);
        arg3.putString("_wximageobject_imagePath", this.imagePath);
    }

    public void setImagePath(String arg1) {
        this.imagePath = arg1;
    }

    public int type() {
        return 2;
    }

    public void unserialize(Bundle arg2) {
        this.imageData = arg2.getByteArray("_wximageobject_imageData");
        this.imagePath = arg2.getString("_wximageobject_imagePath");
    }
}

